import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const commonRouters = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/message',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/message/index.vue'),
        name: 'Message',
        meta: { title: '消息' },
        hidden: true
      }
    ]
  }

]
export const asyncRoutes = [
  {
    path: '/carousel',
    component: Layout,
    redirect: '/carousel/index',
    meta: { title: '轮播图管理', id: 1 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/carousel/index'),
        name: 'Carousel',
        meta: { title: '轮播图管理', icon: 'dashboard', id: 2 }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    meta: { title: '用户管理', id: 3 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'User',
        meta: { title: '用户管理', icon: 'dashboard', id: 4 }
      }
    ]
  },
  {
    path: '/client',
    component: Layout,
    redirect: '/client/index',
    meta: { title: '客户管理', icon: 'dashboard', id: 5 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/client/index'),
        name: 'Client',
        meta: { title: '客户列表', icon: '', id: 6 }
      },
      {
        path: 'order',
        component: () => import('@/views/client/order'),
        name: 'Order',
        meta: { title: '客户订单', icon: '', activeMenu: '/client/index', id: 7 }
      }
    ]
  },
  {
    path: '/designer',
    component: Layout,
    redirect: '/designer/index',
    meta: { title: '设计师管理', icon: 'dashboard', id: 8 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/designer/index'),
        name: 'DesignerList',
        meta: { title: '设计师列表', id: 9 }
      },
      {
        path: 'production',
        component: () => import('@/views/designer/production'),
        name: 'Designer',
        meta: { title: '设计师作品', icon: 'dashboard', activeMenu: '/designer/index', id: 10 },
        hidden: true
      },
      {
        path: 'edit-production',
        component: () => import('@/views/designer/edit-production'),
        name: 'EditProduction',
        meta: { title: '编辑作品', icon: 'dashboard', activeMenu: '/designer/index', id: 11 },
        hidden: true
      },
      {
        path: 'edit-information',
        component: () => import('@/views/designer/edit-information'),
        name: 'EditInformation',
        meta: { title: '编辑资料', icon: 'dashboard', activeMenu: '/designer/index', id: 12 },
        hidden: true
      },
      {
        path: 'point',
        component: () => import('@/views/designer/point'),
        name: 'Point',
        meta: { title: '积分管理', icon: 'dashboard', activeMenu: '/designer/index', id: 13 },
        hidden: true
      },
      {
        path: 'coupon',
        component: () => import('@/views/designer/coupon'),
        name: 'Coupon',
        meta: { title: '优惠券', icon: 'dashboard', activeMenu: '/designer/index', id: 14 },
        hidden: true
      },
      {
        path: 'coupon-status',
        component: () => import('@/views/designer/coupon/coupon-status'),
        name: 'CouponStatus',
        meta: { title: '优惠券名称', icon: 'dashboard', activeMenu: '/designer/index', id: 15 },
        hidden: true
      },
      {
        path: 'apply-list',
        component: () => import('@/views/designer/apply-list'),
        name: 'Applylist',
        meta: { title: '设计师审批', id: 16 }
      },
      {
        path: 'rights-setting',
        component: () => import('@/views/designer/rights-setting'),
        name: 'RightsSetting',
        meta: { title: '权益设置', id: 17 }
      },
      {
        path: 'settled-orders',
        component: () => import('@/views/designer/settled-orders'),
        name: 'SettledOrders',
        meta: { title: '入驻订单', id: 18 }
      }
    ]
  },
  {
    path: '/reservation',
    component: Layout,
    redirect: '/reservation/index',
    meta: { title: '预约列表', id: 19 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/reservation/index'),
        name: 'Reservation',
        meta: { title: '预约列表', icon: 'dashboard', id: 20 }
      }
    ]
  },
  {
    path: '/park-mng',
    component: Layout,
    redirect: '/park-mng/index',
    meta: { title: '停车管理', id: 21 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/park-mng/index'),
        name: 'ParkMng',
        meta: { title: '停车管理', icon: 'dashboard', id: 22 }
      }
    ]
  },
  {
    path: '/brand',
    component: Layout,
    redirect: '/brand/index',
    meta: { title: '品牌管理', id: 23 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/brand/index'),
        name: 'Brand',
        meta: { title: '品牌管理', icon: 'dashboard', id: 24 }
      },
      {
        path: 'brand-setting',
        component: () => import('@/views/brand/brand-setting'),
        name: 'BrandSetting',
        meta: { title: '品牌设置', activeMenu: '/brand/index', id: 25 },
        hidden: true
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/index',
    meta: { title: '活动管理', icon: 'dashboard', id: 26 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/activity/index'),
        name: 'Activity',
        meta: { title: '活动列表', id: 27 }
      },
      {
        path: 'sign-up',
        component: () => import('@/views/activity/sign-up'),
        name: 'SignUp',
        meta: { title: '报名管理',  activeMenu: '/activity/index', id: 28 },
        hidden:true
      },
      {
        path: 'edit',
        component: () => import('@/views/activity/edit'),
        name: 'Edit',
        meta: { title: '编辑活动', icon: 'dashboard', activeMenu: '/activity/index', id: 29 },
        hidden: true
      }
    ]
  },
  {
    path: '/integral',
    component: Layout,
    redirect: '/integral/index',
    meta: { title: '积分商品管理', icon: 'dashboard', id: 30 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/integral/index'),
        name: 'IntegralList',
        meta: { title: '积分商品列表', id: 31 }
      },
      {
        path: 'order',
        component: () => import('@/views/integral/order'),
        name: 'Orders',
        meta: { title: '积分兑换订单', id: 32 }
      },
      {
        path: 'edit',
        component: () => import('@/views/integral/edit'),
        name: 'Integral',
        meta: { title: '编辑商品', icon: 'dashboard', activeMenu: '/integral/index', id: 33 },
        hidden: true
      }
    ]
  },
  {
    path: '/coupon-mng',
    component: Layout,
    redirect: '/integral/index',
    meta: { title: '优惠券管理', icon: 'dashboard', id: 34 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/coupon-mng/index'),
        name: 'CouponMng',
        meta: { title: '优惠券', id: 35 }
      },
      {
        path: 'coupon-status',
        component: () => import('@/views/coupon-mng/coupon/coupon-status'),
        name: 'CouponStatusName',
        meta: { title: '优惠券名称', activeMenu: '/coupon-mng/index', id: 36 },
        hidden: true
      },
      {
        path: 'add-coupon',
        component: () => import('@/views/coupon-mng/coupon/add-coupon'),
        name: 'AddCoupon',
        meta: { title: '添加优惠券', activeMenu: '/coupon-mng/index', id: 37 },
        hidden: true
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/message',
    meta: { title: '优惠券管理', icon: 'dashboard', id: 38 },
    children: [
      {
        path: 'message',
        component: () => import('@/views/system/message'),
        name: 'MessageList',
        meta: { title: '系统消息', id: 39 }
      }
    ]
  },
  {
    path: '/auth',
    component: Layout,
    redirect: '/auth/index',
    meta: { title: '系统设置', icon: 'dashboard', id: 40 },
    children: [
      {
        path: 'index',
        component: () => import('@/views/auth/index'),
        name: 'AuthIndex',
        meta: { title: '权限管理', id: 41 }
      },
      {
        path: 'modify-password',
        component: () => import('@/views/auth/modify-password'),
        name: 'ModifyPassword',
        meta: { title: '修改密码', id: 42 }
      },
      {
        path: 'bind-wx',
        component: () => import('@/views/auth/bind-wx'),
        name: 'BindWx',
        meta: { title: '绑定微信', id: 43 }
      },
      {
        path: 'add-auth',
        component: () => import('@/views/auth/add-auth'),
        name: 'AddAuth',
        meta: { title: '添加权限', activeMenu: '/auth/index', id: 44 },
        hidden: true
      }
    ]
  },
  {
    path: '/operating',
    component: Layout,
    redirect: '/operating/index',
    meta: { title: '操作记录', icon: 'dashboard', id: 46 },
    children: [
      {
        path: 'index',
        component: () => import('../views/operating/index'),
        name: 'OperatingIndex',
        meta: { title: '操作记录', icon: 'dashboard', id: 47 }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
// export const asyncRoutes = [
//   // 404 page must be placed at the end !!!

// ]
export const constantRoutes = [...commonRouters]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
